package com.est.dase.sms;
/**
*
* @author Fernando Geraldes, Jaime Santos, Jorge Silva
*
*/
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;

public class SMS {

	public SMS(){
		super();
	}
	//---sends a SMS message to another device---
    @SuppressWarnings("unused")
	public void sendSMS(String phoneNumber, String message, Context c)
    {      
    	/*
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, test.class), 0);                
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, message, pi, null);        
        */
    	
    	String SENT = "SMS_SENT";
    	String DELIVERED = "SMS_DELIVERED";
    	
        PendingIntent sentPI = PendingIntent.getBroadcast(c, 0,
            new Intent(SENT), 0);
        
        PendingIntent deliveredPI = PendingIntent.getBroadcast(c, 0,
            new Intent(DELIVERED), 0);
        
        
        final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
        final String TAG = "SMSBroadcastReceiver";

    	
//        //---when the SMS has been sent---
//        registerReceiver(new BroadcastReceiver(){
//			@Override
//			public void onReceive(Context arg0, Intent arg1) {
//				 Log.i(TAG, "Intent recieved sent: " + arg1.getAction());
//				 Log.i(SMS_RECEIVED, "Intent recieved sent: " + arg1.getAction().equals(SMS_RECEIVED));
//
//				switch (getResultCode())
//				{
//				    case Activity.RESULT_OK:
//					    Toast.makeText(getBaseContext(), "SMS sent", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
//					    Toast.makeText(getBaseContext(), "Generic failure", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case SmsManager.RESULT_ERROR_NO_SERVICE:
//					    Toast.makeText(getBaseContext(), "No service", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case SmsManager.STATUS_ON_ICC_SENT:
//					    Toast.makeText(getBaseContext(), "Received and read", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case SmsManager.RESULT_ERROR_RADIO_OFF:
//					    Toast.makeText(getBaseContext(), "Radio off", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case SmsManager.STATUS_ON_ICC_UNREAD:
//					    Toast.makeText(getBaseContext(), "Received and unread", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case SmsManager.STATUS_ON_ICC_UNSENT:
//					    Toast.makeText(getBaseContext(), "Stored and unsent", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				}
//			}
//        }, new IntentFilter(SENT));
//        
//        //---when the SMS has been delivered---
//        registerReceiver(new BroadcastReceiver(){
//			@Override
//			public void onReceive(Context arg0, Intent arg1) {
//				Log.i(TAG, "Intent recieved delivered: " + arg1.getAction());
//				Log.i(SMS_RECEIVED, "Intent recieved delivered: " + arg1.getAction().equals(SMS_RECEIVED));
//				
//				switch (getResultCode())
//				{
//				    case Activity.RESULT_OK:
//					    Toast.makeText(getBaseContext(), "SMS delivered", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;
//				    case Activity.RESULT_CANCELED:
//					    Toast.makeText(getBaseContext(), "SMS not delivered", 
//					    		Toast.LENGTH_SHORT).show();
//					    break;					    
//				}
//			}
//        }, new IntentFilter(DELIVERED));        
    	
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    }
}
